/*
 *    Copyright 2022 jacky4631 shen ji email:121659050@qq.com
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.dataoke.shoppingguide.app773026.api.remote;

import static com.dataoke.shoppingguide.app773026.api.ApiHttpClient.post;

import android.text.TextUtils;

import com.dataoke.shoppingguide.app773026.api.ApiHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;

/**
 *
 * @author: shen ji
 * @date: 2022/3/15
 * @email: 121659050@qq.com
 * @wechat: jacky4631
 */
@SuppressWarnings("all")
public class JKJApi {

    public static final String LOGIN_WEIBO = "weibo";
    public static final String LOGIN_QQ = "qq";
    public static final String LOGIN_WECHAT = "wechat";

    public static final int REGISTER_INTENT = 1;
    public static final int RESET_PWD_INTENT = 2;

    public static final int REQUEST_COUNT = 0x50;//请求分页大小



    /**
     * 更改收藏状态
     *
     * @param id      id
     * @param type    type
     * @param handler handler
     */
    public static void getFavReverse(long id, int type, AsyncHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("id", id);
        params.put("type", type);
        ApiHttpClient.get("action/apiv2/favorite_reverse", params, handler);
    }

    public static void checkUpdate(TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("appId", 1);
        params.put("catalog", 1);
        params.put("all", false);
        ApiHttpClient.get("action/apiv2/product_version", params, handler);
    }

    public static void getCollectionList(String pageToken, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("catalog", 0);
        params.put("pageToken", pageToken);
        ApiHttpClient.get("action/apiv2/favorites", params, handler);
    }

    /**
     * @param catalog  open catalog
     * @param openInfo openInfo
     * @param handler  handler
     */
    public static void openLogin(String catalog, String openInfo, TextHttpResponseHandler handler) {
        if (TextUtils.isEmpty(openInfo)) return;
        RequestParams params = new RequestParams();
        params.put("catalog", catalog);
        params.put("info", openInfo);

        post("action/apiv2/account_open_login", params, handler);
    }

    /**
     * login account
     *
     * @param username username
     * @param pwd      pwd
     * @param handler  handler
     */
    public static void login(String username, String pwd, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("account", username);
        params.put("password", pwd);
        post("action/apiv2/account_login", params, handler);
    }

    public static void sendSmsCode(String phone, int intent, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("phone", phone);
        params.put("intent", intent);
        post("action/apiv2/phone_send_code", params, handler);
    }


    /**
     * validate and get phone token
     *
     * @param phoneNumber phoneNumber
     * @param smsCode     smsCode
     * @param handler     handler
     */
    public static void validateRegisterInfo(String phoneNumber, String smsCode, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("phone", phoneNumber);
        params.put("code", smsCode);
        post("action/apiv2/phone_validate", params, handler);
    }


    /**
     * register user info
     *
     * @param username   username
     * @param password   pwd
     * @param gender     gender
     * @param phoneToken token
     * @param handler    handler
     */
    public static void register(String username, String password, int gender
            , String phoneToken, TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("username", username);
        params.put("password", password);
        params.put("gender", gender);
        params.put("phoneToken", phoneToken);

        post("action/apiv2/account_register", params, handler);
    }

    /**
     * reset pwd
     *
     * @param password   password
     * @param phoneToken token
     * @param handler    handler
     */
    public static void resetPwd(String password, String phoneToken
            , TextHttpResponseHandler handler) {
        RequestParams params = new RequestParams();
        params.put("password", password);
        params.put("phoneToken", phoneToken);

        post("action/apiv2/account_password_forgot", params, handler);
    }

}
